package com.cloudsigns.factorymanager2.produce.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.cloudsigns.factorymanager2.BaseActivity;
import com.cloudsigns.factorymanager2.R;
import com.cloudsigns.factorymanager2.cusenum.CommonEnum;
import com.cloudsigns.factorymanager2.engineering.customview.ListViewForScrollView;
import com.cloudsigns.factorymanager2.produce.adapter.ProduceModifyPlanInformationAdapter;
import com.cloudsigns.factorymanager2.produce.bean.WorkPartBean;
import com.cloudsigns.factorymanager2.produce.bean.WorkPartDailyFeedbackBean;
import com.cloudsigns.factorymanager2.produce.bean.WorkPartFeedbackResponse;
import com.cloudsigns.factorymanager2.produce.bean.request.WorkPartScheduleItemRequest;
import com.cloudsigns.factorymanager2.produce.iview.produce_team.IWorkPartDetailView;
import com.cloudsigns.factorymanager2.produce.presenter.produce_team.WorkPartDetailPresenter;
import com.cloudsigns.factorymanager2.project.utils.ConstantUtil;

public class ProduceModifyPlanInformationActivity extends BaseActivity implements IWorkPartDetailView {
    private RelativeLayout rl_back;
    private TextView tv_title;
    private TextView tv_cycle_type;
    private ListViewForScrollView lv_cycle;

    private WorkPartFeedbackResponse workPartFeedbackResponse;
    private WorkPartDailyFeedbackBean workPartDailyFeedbackBean;

    private ProduceModifyPlanInformationAdapter adapter;
    private WorkPartScheduleItemRequest workPartScheduleItemRequest= new WorkPartScheduleItemRequest();
    private WorkPartDetailPresenter workPartDetailPresenter;

    @Override
    protected void onBaseCreate(Bundle savedInstanceState) {
        setContentView(R.layout.layout_produce_modify_plan_information);
    }

    @Override
    protected void initView(Bundle savedInstanceState) {
        rl_back=findViewById(R.id.rl_back);
        tv_title=findViewById(R.id.tv_title);
        tv_cycle_type=findViewById(R.id.tv_cycle_type);
        lv_cycle=findViewById(R.id.lv_cycle);
    }

    @Override
    protected void initData(Bundle savedInstanceState) {
        tv_title.setText(getResources().getString(R.string.plan_infor));

        Intent intent = getIntent();
        workPartFeedbackResponse = (WorkPartFeedbackResponse) intent.getSerializableExtra(ConstantUtil.KEY_1);
        workPartDailyFeedbackBean = (WorkPartDailyFeedbackBean) intent.getSerializableExtra(ConstantUtil.KEY_2);

        workPartDetailPresenter = new WorkPartDetailPresenter(this);
        workPartDetailPresenter.workPartDetail();

        adapter=new ProduceModifyPlanInformationAdapter(this);
    }

    @Override
    public void setListener() {
        rl_back.setOnClickListener(this);
    }

    @Override
    public void widgetClick(View view) {
switch (view.getId()){
    case R.id.rl_back:
        finish();
        break;
}
    }

    @Override
    public String getOrderId() {
        return workPartFeedbackResponse.getOrderId();
    }

    @Override
    public String getProductId() {
        return workPartFeedbackResponse.getProductId();
    }

    @Override
    public String getWorkPartId() {
        return workPartFeedbackResponse.getWorkPartId();
    }

    @Override
    public String getWorkPartOrderId() {
        return workPartFeedbackResponse.getWorkPartOrderId();
    }

    @Override
    public void workPartDetailSueecssed(WorkPartBean workPartBean) {
        if (null != workPartBean) {
            CommonEnum.WorkPartType type = workPartFeedbackResponse.getType();
            if (null != type) {
                if (type == CommonEnum.WorkPartType.APPLY_ADJUST) {
                    tv_cycle_type.setText(getResources().getString(R.string.adjust_cycle));
                    workPartScheduleItemRequest.getSpecifiedDayAfter(workPartBean.getCompleteDate(),workPartDailyFeedbackBean.getApplyDays());

                } else  if (type == CommonEnum.WorkPartType.APPLY_RETURN) {
                    tv_cycle_type.setText(getResources().getString(R.string.rework_cycle));
                    workPartScheduleItemRequest.getSpecifiedDayAfter(workPartBean.getCompleteDate(),workPartDailyFeedbackBean.getApplyDays());

                } else if (type == CommonEnum.WorkPartType.APPLY_SCRAP) {
                    tv_cycle_type.setText(getResources().getString(R.string.tv_scrap_cycle));
                    workPartScheduleItemRequest.getSpecifiedDayAfter(workPartBean.getCompleteDate(),workPartDailyFeedbackBean.getApplyDays());
                }
            }

            adapter.setData(workPartScheduleItemRequest.getWorkPartScheduleItemRequestList());
            lv_cycle.setAdapter(adapter);
        }
    }

    @Override
    public void workPartDetailFailed(final String desc) {
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                showToast(desc);
            }
        });
    }

    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }
}
